height[100000],count[100000];
long answer,temp;
main(i,n,value,j,tail)
{
	for(;scanf("%d%d",&n,height)-1;printf("%ld\n",answer))
	{
		for(*count=i=1,answer=*height,tail=0;i++<n;)
		{
			scanf("%d",&value);
			if(height[tail]<value)
			{
				height[++tail]=value;
				count[tail]=0;
			}
			else if(height[tail]>value)
			{
				while(~tail&&height[tail]>=value)
				{
					temp=1L*height[tail]*count[tail];
					answer=answer>temp?answer:temp;
					tail--;
				}
				height[++tail]=value;
/*
				for(j=0;j<=tail;j++)
				{
					printf(" %d",height[j]);
				}
				puts("");
*/
			}

			for(j=0;j<=tail;temp=1L*height[j]*count[j++],answer=answer>temp?answer:temp)count[j]++;

		}
	}
}
